
<template>
    <div class="chinnelInfoMain">
        <div class="infolist">
          <div class="headerSelection">
            <split-vertical title="平台信息"></split-vertical>
            <v-form :formProps="searchForm" ref="form"
                    v-on:handleReset="handleReset"
                    v-on:coverFormData="coverFormData">
            </v-form>
          </div>
          <div class="stand">
            <div style="line-height:50px;margin-left:10px;">
              <v-button :operationBtnArray="operationBtnArray" v-on:handleSearchTopBtn="handleSearchTopBtn"></v-button>
            </div>
            <div style="margin:0 10px;">
              <v-table :tableParams="tableParams" v-on:handleOperation="handleOperation"></v-table>
            </div>
          </div>
        </div>
        <div class="block">
            <el-pagination
                @current-change="handleCurrentChange"
                :current-page="pageIndex"
                :page-sizes="[10]"
                :page-size="10"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageCount">
            </el-pagination>
        </div>
        <!-- //编辑信息 -->
        <update v-if="show2" :add='add' @closeDialog='closeDialog'></update>
           <!-- 创建信息 -->
        <add v-if="show" @closeDialog='closeDialog'></add>
    </div>
</template>
<script>
import VTable from "components/common/PageTable/VTable"
import add from 'components/base/platformInfo/add'
import update from 'components/base/platformInfo/update'
import SplitVertical from "components/common/SplitVertical"
import VForm from "components/common/VForm"
import VButton from "components/common/VButton"
let nature={
  "A":"银行",
  "B":'电商'
}
export default {
    components:{
      add, update,VTable,SplitVertical,VForm,VButton
    },
    inject:['reload'],
    data(){
        return{
            searchCondition:{},
            pageCount: 0,
            pageIndex:1,
            pageSize:10,
            show:false,//控制创建公司信息的显示
            show2:false,//控制编辑公司信息的显示
            //编辑传的对象
            add:{},
            row:{},
            searchForm: {
              col: 3,
              labelWidth: '100px',
              submitBtn: {
                text: '搜索'
              },
              formItemArray: [{
                label: '平台名称',
                prop: 'platformName',
                placeholder: "请输入",
                value: ''
                },
                {
                  label: '平台性质',
                  prop: 'platformNature',
                  placeholder: "请输入供应商编码",
                  value: '',
                  itemType: 'select',
                  options: [
                    {id:1,value:"A",label:"银行"},
                    {id:2,value:"B",label:"电商"}
                  ],

                },{
                label: '状态',
                prop: 'status',
                placeholder: "请输入供应商编码",
                value: '',
                itemType: 'select',
                options: [
                  {id:1,value:0,label:"禁用"},
                  {id:2,value:1,label:"启用"}
                ],

              }]
            },
            operationBtnArray: [{
              text: '刷新',
              show: true,
              icon:'el-icon-refresh',
              type: 'primary',
              methodName: 'refresh',
            }, {
              text: '新增',
              icon:'el-icon-plus',
              show: true,
              type: 'success',
              methodName: 'add',
            }],
            tableParams:{
                dataArray:[],
                showMultiSelection:false,
                columnArray:[
                    {label: '平台性质', prop: 'platformNature',sortable: false},
                    {label: '组织机构代码', prop: 'organizationCode',sortable: false},
                    {label: '平台名称', prop: 'platformName',sortable: false},
                    {label: '合作公司', prop: 'companyName',  sortable: false},

                ],
                rowHandle:{
                    view:{
                        show:false
                    }
                }
            },
          id:''
        }
    },
    created(){
      this.init()
    },
    methods:{
        init(){
           this.listVal()

        },

        handleSearchTopBtn(methodName) {
          if (methodName === "refresh") {
            this.refresh();
          } else {
            this.create();
          }
        },
        handleReset(formName) {
          this.$refs.form.resetForm(formName);
        },
        coverFormData(data) {
          this.searchCondition = data;
          this.query()
        },
        handleOperation(rowIndex, row, methodName) {
            this.id=row.id;
            this.row=row;
            if(methodName == "update"){
              this.modifyChannelInfo()
            }else if(methodName == "delete"){
              this.delchannel()
            }
        },
        //刷新
        refresh(){
            this.listVal()
        },
        closeDialog(){
            this.show2 = false;
            this.show = false;
        },
        //初始化新增渠道信息的表格
        listVal(){
            let parmas={
               page:{
                 pageIndex:1,
                 pageSize:10
               }
            }
            let success=data=>{
                if(data.statusCode === '1'){
                    this.tableParams.dataArray=data.body.records
                    this.tableParams.dataArray.forEach((ele)=>{
                      ele.platformNature=nature[ele.platformNature]
                    })
                    this.pageCount = data.body.count
                } else{
                    this.$message.error(data.statusMessage)
                }
            }
            this.api.platformList(parmas,success)
        },
        //编辑表格信息
        modifyChannelInfo(){
          this.show2=true
            let parmas={
               id:this.id
            }
            let success=data=>{
                if(data.statusCode == '1'){
                    this.add=data.body
                }else{
                    this.$message.error(data.statusMessage)
                }
            }
            this.api.platformGetOne(parmas,success)
        },
        //查询
        query(){
            let param = this.searchCondition;
            param['page']={
              pageIndex:this.pageIndex,
              pageSize:this.pageSize
            }
            let success = data => {
              if (data.statusCode === '1') {
                this.pageCount = data.body.count;
                this.tableParams.dataArray=data.body.records
                this.tableParams.dataArray.forEach((ele)=>{
                  ele.platformNature=nature[ele.platformNature]
                })
              } else {
                this.$message.error(data.msg);
              }
            };
            this.api.platformList(param,success)
        },
        //删除表格信息
        delchannel(){
          this.tips.ConfirmModal('确认要删除该平台名称为【'+this.row.platformName+'】吗？', () => {
            let parmas={
              id:this.id
            }
            let success=data=>{
              if(data.code=='statusCode'){
                this.reload()
                this.$message.success("删除成功")
              }else{
                this.$messsage.error(data.statusMessage)
              }
            }
            this.api.platformDelete(parmas,success)
          });
        },
        //创建渠道信息
        create(){
            this.show=!this.show;
        },
      //当前页
      handleCurrentChange: function (val) {
          this.pageIndex = val;
          this.query()
      }
    },
}
</script>

<style lang="scss" scoped>
.chinnelInfoMain{

   .infolist{
     .headerSelection{
       background:#fff;
       height:140px;
       padding: 0 10px;
       border-left: 2px solid #e8e8e8;
       border-right: 2px solid #e8e8e8;
       border-bottom: 2px solid #e8e8e8;
     }
     .stand{
       background:#fff;
     }
   }
  .block{
    padding: 10px 0;
    text-align: right;
  }
}
</style>



